Replace Override App Bar Back Button In Flutter Android

admin_img Posted By Bajarangi soft , Posted On 10-10-2020

App Bar back button is base of every mobile application which has multiple activities screens. Using the App Bar back button mobile UI provides simple navigation to their app users to go back to previous screen. By default the back arrow button is fixed in every flutter android iOS application but we can easily change it by using custom Icons or widgets.

replace-override-app0bar-back-button-in-flutter-android

Replace Override App Bar Back Button
Complete Code For Replace Override App Bar Back Button In Flutter
main.dart

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    debugShowCheckedModeBanner: false,
    title: 'Flutter Navigate to Next Screen',
    home: FirstScreen(),
  ));
}

class FirstScreen extends StatelessWidget {
  gotoNextActivity(BuildContext context){
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => SecondScreen()),
    );
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0xFF880E4F),
        title: Text('Home Activity Screen'),
      ),
      body: Center(
        child: RaisedButton(
            child: Text('Navigate To Second Screen'),
            color: Colors.pink,
            textColor: Colors.white,
            onPressed: () {
              gotoNextActivity(context);
            }),

      ),
    );
  }
}
class SecondScreen extends StatelessWidget {
  goBack(BuildContext context){
    Navigator.pop(context);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
          backgroundColor: Color(0xFF880E4F),
          automaticallyImplyLeading: true,
          title: Text('OverRide AppBar BACK Button'),
          leading: IconButton(icon:Icon(Icons.home),
            onPressed: () {goBack(context);},
          )
      ),

      body: Center(
        child: RaisedButton(
          onPressed: () {goBack(context);},
          color: Colors.pink,
          textColor: Colors.white,
          child: Text('Go Back To Previous Screen'),
        ),
      ),
    );
  }
}

Related Post